import java.util.Arrays;

public class Array_0728 {
    public static void main5(String[] args) {
        int[] array = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
        swapArray(array);
        System.out.println(Arrays.toString(array));

    }

    public static void transfrom(int[] array1) {
        int n = array1.length;
        for (int i = 0; i < array1.length; i++) {
            array1[i] = array1[i] * 2;
        }
    }

    public static void swapArray(int[] array) {
        int j = array.length - 1;
        int i = 0;
        while (i < j) {
            if (i < j && array[i] % 2 != 0)//array[i]为奇数
                i++;
            else {
                while (i < j && array[j] % 2 == 0) {
                    j--;
                }
                int tmp = array[i];
                array[i] = array[j];
                array[j] = tmp;
            }
        }
    }

    public static void binarySearch(int[] array, int ret) {
        int i = 0;
        int j = array.length - 1;
        while (i <= j) {
            int mid = (i + j) / 2;
            if (ret == array[mid]) {
                System.out.println("找到了，下标是" + mid);
                break;
            } else {
                if (ret > array[mid]) {
                    i = mid + 1;
                } else {
                    j = mid - 1;
                }
            }
        }
        if (i > j) {
            System.out.println("没找到");
        }
    }

    public static void main(String[] args) {
        int[] array = new int[]{1, 3, 5, 7, 9, 10, 11};
        binarySearch(array, 5);
        binarySearch(array, 1);
        binarySearch(array, 11);
        binarySearch(array, 4);
        System.out.println(Arrays.toString(targetNums(array,8)));
        int[] array2 = new int[]{1,2,1,2,9,5,5,6,8,8,6};
        System.out.println(onlyOneTimeInArray(array2));
        System.out.println("===========================");
        int[] array3=new int[]{1,2,3,4,5,6,7,9,10,5};
        int[] array4=new int[]{1,2,3,4,5,6,7,9,11,10,5};
        System.out.println(threeTimesInArray((array3)));
        System.out.println(threeTimesInArray((array4)));
        System.out.println("===========================");
        int[] array5={1,2,3,5,6,2,2,8,2,4,2,2,2};
        System.out.println(func(array5));
    }

    public static int[] targetNums(int[] nums, int target) {
        int[] ret = {-1, -1};
        int i = 0;
        int j = nums.length - 1;
        for (int k = 0; k < nums.length - 1; k++) {
            for (int l = k + 1; l < nums.length - 1; l++) {
                if (nums[l] + nums[k] == target) {
                    ret[0] = l;
                    ret[1] = k;
                    return ret;
                }
            }
        }
        return ret;
    }
    public static int onlyOneTimeInArray(int[] array) {
        int n=array[0];
        for (int i = 1; i <array.length ; i++) {
            n=n^array[i];
        }
        return n;
    }

    public static boolean threeTimesInArray(int[] arr) {
        for (int i = 0; i <arr.length-2 ; i++) {
            if(arr[i]%2!=0&&arr[i+1]%2!=0&&arr[i+2]%2!=0) {
                return true;
            }
        }
        return false;
    }

    public static int func(int[] array) {
        int ret=0;
        int count=0;
        for (int i = 0; i < array.length; i++) {
            ret=array[i];
            for (int j = 0; j < array.length; j++) {
                if(ret==array[j])
                    count++;

            }
            if(count>array.length/2)
                return ret;
        }
        return -1;
        }

}
